<template>
	<view class="contain">
		<view class="tables" style="margin-top:10px;">
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="mid blod">日期</view>
				</u-col>
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="mid blod">套餐</view>
				</u-col>
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="mid blod">金额</view>
				</u-col>
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="mid blod">状态</view>
				</u-col>
			</u-row>
		</view>
		<view class="tables" style="margin-top:10px;border-bottom:0px;" v-for="item in SubScribes.data">
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="small">{{item.createtime}}</view>
				</u-col>
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="small">{{item.productname}}</view>
				</u-col>
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="small" style="color:#00a100;">{{ formatPrice(item.orderprice) }}</view>
				</u-col>
				<u-col span="3" justify="center" align="center" textAlign="center">
					<view class="small" v-if="item.paystatue==='已支付'" style="color:#00a100">{{item.paystatue}}</view>
					<view class="small" v-else style="color:#ff3535" @click="gopay(item)">{{item.paystatue}}</view>
				</u-col>
			</u-row>
		</view>
	</view>
</template>

<script setup lang='ts'>
import { ref,reactive } from 'vue'
import { onLoad,onShow } from '@dcloudio/uni-app'
import { userStore } from '@/stores/userStore'
let store = userStore();	
let { hasLogin,userData } = userStore();

let SubScribes=reactive({data:[
	// {
	// 	"createtime":"2024-07-13",
	// 	"productname":"套餐A-老年人痴呆访谈 x1",
	// 	"orderprice":"93.8",
	// 	"paystatue":"未支付",
	// },
	// {
	// 	"createtime":"2024-07-13",
	// 	"productname":"套餐A-老年人痴呆访谈 x1",
	// 	"orderprice":"93.8",
	// 	"paystatue":"已支付",
	// }
]});
let isLoad=ref(false);

const formatPrice=(price:string | number)=>{
	if(typeof(price)==='string') return parseFloat(price)/100;
	return price/100;
}

const gopay=(item:any)=>{
	if(item!=null && item.productname===("测评屋")){
		return uni.$tools.GoUrl("/pages/cepingbuy/cepingbuy",1); //跳转到登录
	}
	if(item!=null && item.productname===("认知行为成长站套餐")){
		return uni.$tools.GoUrl("/pages/buy/buy",1); //跳转到登录
	}
	return uni.$tools.GoUrl("/pages/index/index",1); //跳转到登录
}

/* 查询充值 */
const getOrders=()=>{
	console.log("用户id",userData.userinfo.id);
	let paraData={
		userid:userData.userinfo.id,
		paystatue:'已支付'
	};
	uni.$tools.Reqeust('/api/getSJorders',paraData,'POST').then((res:any)=>{
			console.log('查询充值结果:',res);
			if (res.data.code == 200) {
				SubScribes.data=res.data.ordersList;
			}else{
				uni.$tools.Toast(res.data.msg);
			}
	})	
}

onLoad(()=>{
	getOrders();
});

onShow(()=>{

})

</script>

<style lang='scss' scoped>
	@import "sjorders.scss";
</style>